package Operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class  AddOperation implements IOperation{
    @Override
    public void work(BookList books) {
        Scanner scanner=new Scanner(System.in);
        System.out.println("增加图书！");
        System.out.println("输入书名:");
        String name=scanner.next();
        System.out.println("请输入作者:");
        String author=scanner.next();
        System.out.println("请输入价格:");
        int price=scanner.nextInt();
        System.out.println("请输入类型:");
        String type=scanner.next();
        Book book=new Book(name,author,price,type);
        for (int i=0;i<books.getUserSize();i++) {
            Book book1= books.getBooks(i);//将返回的引用给book
            if(book1.getName().equals(name))//用book去调用Book类的getName
            {
                System.out.println("要添加的书已经存在,不能添加");
                return;
            }
        }
        books.setBooks(book);
        books.setUserSize(books.getUserSize()+1);
        System.out.println("添加成功 ");
    }


}
